package net.hnjdzy.newsclient;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class register extends AppCompatActivity {
    private EditText ed1,ed2,ed3,ed4;
    private Button bon;
    private  bean bb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        bon =(Button) findViewById(R.id.regeste);
        bon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url="http://39.99.228.8:8080/news/servlet/ApiServlet?opr=register";
                reges a =new reges();
                 a.execute(url);
            }
        });
    }

    class  reges  extends AsyncTask<String,Void,bean>{
        @Override
        protected bean doInBackground(String... strings) {
            String u = strings[0];
            OkHttpClient client= new OkHttpClient();
            //请求体
            RequestBody body =new FormBody.Builder()
                    .add("uname","123")
                    .add("upwd","123465")
                    .build();
            Request request =new Request.Builder().url(u).post(body).build();
            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {

                }

                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                    if(response.code() ==200){
                        String string = response.body().string();
                        
                    }
                }
            });
            return null;
        }

        @Override
        protected void onPostExecute(bean bean) {
          ed1 =(EditText) findViewById(R.id.pwd);
          ed2 =(EditText) findViewById(R.id.phone);
          ed3 =(EditText) findViewById(R.id.pwd2);
          ed4=(EditText) findViewById(R.id.ni);

            if (!ed1.getText().toString().equals(ed3.getText().toString())) {
                Toast.makeText(register.this, "密码不一样", Toast.LENGTH_SHORT).show();
            } else {

                Intent intent = new Intent(register.this,Logon.class);
                startActivity(intent);
            }


            }
        }


    }


